package com.zbb.base.execption;

import com.zbb.base.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
@ResponseBody
@ExceptionHandler(ZbbBackException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result customException(ZbbBackException e) {
log.error("【系统异常】{}",e.getErrMessage(),e);
return Result.fail(e.getErrMessage());
}
@ResponseBody
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result exception(Exception e) {
log.error("【系统异常】{}",e.getMessage(),e);
return  Result.fail(CommonError.UNKOWN_ERROR.getErrMessage());
}
}